﻿using System;

namespace eProject.ViewModel
{
    public class ActivityDetailizationViewModel : ViewModelBase
    {
        public ActivityDetailizationViewModel(ActivityViewModel activity, DateTime date, double manHours)
            : this(activity)
        {
            Date = date;
            ManHours = manHours;
        }

        public ActivityDetailizationViewModel(ActivityViewModel activity)
        {
            Activity = activity;
        }

        public ActivityViewModel Activity { get; private set; }

        public DateTime Date
        {
            get { return _date; }
            set
            {
                if (value == _date) return;
                _date = value;
                var day = Activity.Employee.GetManHours(Date);
                Percent = day == 0 ? 0 : _manHours/day;
                InvokePropertyChanged("Date");
            }
        }

        public double ManHours
        {
            get { return _manHours; }
            set
            {
                if (value == _manHours) return;
                _manHours = value;
                var day = Activity.Employee.GetManHours(Date);
                Percent = _manHours/day;
                InvokePropertyChanged("ManHours");
            }
        }

        public double Percent
        {
            get { return _percent; }
            private set
            {
                if (_percent == value) return;
                _percent = value;
                InvokePropertyChanged("Percent");
            }
        }

        private double _percent;

        private DateTime _date;

        private double _manHours;

    }
}
